#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int n;
	cin>>n;
	string str;
	cin>>str;
	
	str=' '+str;
	vector<char> dp;
	int ret=0;
	for(int i=1;i<=n;i++)
	{
		if(dp.empty() || str[i]>=dp[dp.size()-1])
		{
			dp.push_back(str[i]);
		}
		else{
			int left=0,right=dp.size()-1;
			while(left<right)
			{
				int mid=(right+left)>>1;
				if(dp[mid]>str[i])
				{
					right=mid;
				}
				else{
					left=mid+1;
				}
			}
			dp[left]=str[i];
		}
	}
	cout<<n-dp.size()<<endl;
	return 0;
}
